﻿// -----------------------------
// Copyright © Kodi Studios 2012
// -----------------------------

using System.IO;

namespace Kodi.Picturethrill
{
    /// <summary>
    /// Caches Images from previous days
    /// </summary>
    class CacheServiceWrapper
    {
        #region Private Fields
        private string installedCacheFileName = Path.Combine(Settings.CurrentProcessDirectoryPath, "InstalledCache.xml");
        private CacheService installedCache = new CacheService();

        private string latestCacheFileName = Path.Combine(Settings.TempPath, "WallpapersCache.xml");
        private CacheService latestCache = new CacheService();
        #endregion

        public void Cache(string providerName, string fileName)
        {
            this.latestCache.Cache(providerName, fileName);
        }

        internal string GetCached(string providerName)
        {
            string cachedImage = string.Empty;
            cachedImage = latestCache.GetCached(providerName);
            if (string.IsNullOrEmpty(cachedImage))
            {
                cachedImage = installedCache.GetCached(providerName);
            }

            return cachedImage;
        }


        public void Load()
        {
            this.installedCache.Load(installedCacheFileName, Path.Combine(Settings.CurrentProcessDirectoryPath, "InstalledCache"));
            this.latestCache.Load(latestCacheFileName, Settings.WallpaperCachePath);
        }

        public void Save()
        {
            this.latestCache.Save(latestCacheFileName);
        }

        public void RemoveNonCached()
        {
            this.latestCache.RemoveNonCached();
        }
    }
}
